package com.bridgeintelligent.tag.combination.controller;

import com.bridgeintelligent.tag.combination.entity.CombinationPage;
import com.bridgeintelligent.tag.combination.entity.Result;
import com.bridgeintelligent.tag.combination.pojo.Combination;
import com.bridgeintelligent.tag.combination.service.ICombinationApprovalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 组合标签审批控制层
 */
@Slf4j
@Api(tags = "组合标签审批")
@RestController
@RequestMapping("/api/combinationApproval")
public class CombinationApprovalController {

    @Autowired
    private ICombinationApprovalService combinationApprovalService;

    /**
     * 新增组合标签提交审批
     *
     * @param dimId
     * @return
     */
    @ApiOperation(value = "新增组合标签提交审批", notes = "组合标签提交审批")
    @PostMapping("addCommit")
    public Result addCommit(String dimId) {
        combinationApprovalService.addCommit(dimId);
        return new Result(0);
    }


    /**
     * 新增组合标签审批通过
     *
     * @param dimId
     * @return
     */
    @ApiOperation(value = "新增组合标签审批通过", notes = "组合标签审批通过")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "dimId", value = "标签id"),
            @ApiImplicitParam(paramType = "query", name = "instanceId", value = "实例ID")
    })
    @PostMapping("addPass")
    public Result addPass(String dimId,String instanceId) {
        combinationApprovalService.addPass(dimId,instanceId);
        return new Result(0);
    }

    /**
     * 审批驳回
     *
     * @param dimId
     * @param desc
     * @return
     */
    @ApiOperation(value = "审批驳回", notes = "组合标签审批驳回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "dimId", value = "标签id"),
            @ApiImplicitParam(paramType = "query", name = "instanceId", value = "实例ID"),
            @ApiImplicitParam(paramType = "query", name = "desc", value = "驳回原因")
    })
    @PostMapping("Reject")
    public Result reject(String dimId, String instanceId ,String desc) {
        combinationApprovalService.reject(dimId, instanceId, desc);
        return new Result(0);
    }

    /**
     * 重新提交审批
     *
     * @param dimId
     * @return
     */
    @ApiOperation(value = "重新提交审批", notes = "组合标签重新提交审批")
    @PostMapping("resubmit")
    public Result resubmit(String dimId) {
        combinationApprovalService.resubmit(dimId);
        return new Result(0);
    }

    /**
     * 审批列表
     *
     * @param pageNumber
     * @param pageSize
     * @param dimName
     * @param approveType
     * @param approveState
     * @param uptTimeStart
     * @param uptTimeEnd
     * @return
     */
    @ApiOperation(value = "审批列表", notes = "组合标签审批列表")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "pageNumber", value = "页码"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "条数"),
            @ApiImplicitParam(paramType = "query", name = "dimName", value = "标签名"),
            @ApiImplicitParam(paramType = "query", name = "approveType", value = "申请类型"),
            @ApiImplicitParam(paramType = "query", name = "approveState", value = "审批状态"),
            @ApiImplicitParam(paramType = "query", name = "uptTimeStart", value = "更新时间筛选（开始）"),
            @ApiImplicitParam(paramType = "query", name = "uptTimeEnd", value = "更新时间筛选（结束）")
    })
    @GetMapping("findList")
    public Result findList(Integer pageNumber, Integer pageSize, String dimName, String approveType, String approveState, String uptTimeStart, String uptTimeEnd) {
        pageNumber = pageNumber == null ? 1 : pageNumber;
        pageSize = pageSize == null ? 10 : pageSize;
        CombinationPage<Combination> combinationPage = combinationApprovalService.findList(pageNumber, pageSize, dimName, approveType, approveState, uptTimeStart, uptTimeEnd);
        return new Result(0,combinationPage);
    }

    /**
     * 获取所有的申请类型
     *
     * @return
     */
    @ApiOperation(value = "获取所有的申请类型", notes = "组合标签审批类型")
    @GetMapping("findApproveType")
    public Result findApproveType() {
        Map map = combinationApprovalService.findApproveType();
        return new Result(0,map);
    }



}
